// import interface.
#include <Windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <setjmp.h>

jmp_buf jmpbuf1;
jmp_buf jmpbuf2;

DWORD WINAPI thread1(PVOID para) {
	if (setjmp(jmpbuf2)) {
		puts("thread func error");
	} else {
		puts("thread func have error, throw it.");
		longjmp(jmpbuf2, 1);

		// execute it?
		puts("-");
	}
	puts("thread func return");
	return 0;
}

int main(int argc, char* argv[]) {
	if (setjmp(jmpbuf1)) {
		puts("main func error");
	} else {
		puts("main func have error, throw it.");
		longjmp(jmpbuf1, 1);

		// execute it?
		puts("+");
	}
	puts("main func return");

	{
		HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, thread1, NULL,
				0, NULL);
		assert(hThread);
		WaitForSingleObject(hThread, INFINITE);
		CloseHandle(hThread);
	}
	return 0;
}
